package com.fishbone.core.boot.processor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.time.LocalDateTime;

/**
 * <p>
 *     环境后处理器，可以针对性的
 *     对自己的应用程序进行自定义
 *     环境的扩展。
 * </p>
 * @ClassName FishBoneEnvironmentPostProcessor
 * @Author huyaxi
 * @DATE 2020/4/30 16:56
 */
public class FishBoneEnvironmentPostProcessor implements EnvironmentPostProcessor {

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        System.out.println(LocalDateTime.now() + " INFO " + getVmVendor() + " --- [" + Thread.currentThread().getName() + "] " + this.getClass().getName() + ": " + "CustomEnvironmentPostProcessor: >> 自定义环境处理器,可以参考DevToolsPropertyDefaultsPostProcessor的实现 >>");
    }

    private String getVmVendor(){
        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        return runtimeMXBean.getVmVendor();
    }
}
